package com.gxa.controller;

import com.gxa.pojo.Current;
import com.gxa.service.CurrentService;
import com.gxa.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/current")
public class CurrentController {
    @Resource
    private CurrentService currentService=null;
    //诊断
    @PostMapping("/findById")
    @ResponseBody
    public Map findById( @RequestBody Map<String,String> map){
        Integer id = Integer.valueOf(map.get("id"));
        JsonResult jsonResult = new JsonResult();
        if(id==null||id.equals("")){
            jsonResult.setMsg("");
        }
        Current byId = currentService.findById(id);
        jsonResult.setData(byId);
        return jsonResult.getValues();
    }
    //辅助
    @PostMapping("/findAuxiliary")
    @ResponseBody
    public Map findAuxiliary(Integer id){
        Current auxiliary = currentService.findAuxiliary(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(auxiliary);
        return jsonResult.getValues();
    }
    //根据id查询药物信息
    @PostMapping("/findMedicine")
    @ResponseBody
    public Map findMedicine(Integer id){
        Current medicine = currentService.findMedicine(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(medicine);
        return jsonResult.getValues();
    }
    //根据id查询特殊自疗
    @PostMapping("/findSpecial")
    @ResponseBody
    public Map findSpecial(Integer id){
        Current special = currentService.findSpecial(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(special);
        return jsonResult.getValues();
    }
    //更新所有可以分段更新
    @PostMapping("/update")
    @ResponseBody
    public  Map update(@RequestBody Current current){
        JsonResult jsonResult = new JsonResult();
        Integer id = current.getId();
        if (id!=null||!id.equals("")){
            jsonResult.setCode("204");
            jsonResult.setMsg("id不能为空");
            return jsonResult.getValues();
        }
        boolean update = currentService.update(current);

        if(update!=true){
            jsonResult.setCode("203");
            jsonResult.setMsg("修改失败");
            return jsonResult.getValues();
        }
        jsonResult.setCode("201");
        jsonResult.setMsg("修改成功");
        return jsonResult.getValues();
    }


    //查询所有的数据
    @PostMapping("/findById2")
    @ResponseBody
    public Map findById2(@RequestBody Map<String,String>map){
        Integer id = Integer.valueOf(map.get("id"));
        JsonResult jsonResult = new JsonResult();
        if(id==null||id.equals("")){
            jsonResult.setCode("600");
            jsonResult.setMsg("id不能为空");
            return jsonResult.getValues();
        }
        Current byId2 = currentService.findById2(id);
        jsonResult.setCode("200");
        jsonResult.setData(byId2);
        return jsonResult.getValues();
    }
}
